import { tt } from "../../ttapi_interface/ttapi.js";
import * as tt2 from "../../ttapi_layer2/ttlayer2.js";

export class EUI_Window {
    constructor(canvas: tt2.QUI_Canvas) {
        this.canvas = canvas;
        this.back = new tt2.QUI_Container();
        this.back.localRect.setAsFill();
        canvas.addChild(this.back);

        this.poplayer = new tt2.QUI_Container();
        this.poplayer.localRect.setAsFill();
        canvas.addChild(this.poplayer);
    }
    canvas: tt2.QUI_Canvas
    back: tt2.QUI_Container;
    poplayer: tt2.QUI_Container;
    PushModel(elem: tt2.QUI_IElement, tag: string = "", overlayfunc: (() => void) | null = null): void {
        let m = new tt2.QUI_Container();
        (m as any).tag = tag;
        m.localRect.setAsFill();
        let o = new tt2.QUI_Overlay();
        o.localRect.setAsFill();
        if (overlayfunc != null) {
            o.OnPress = overlayfunc;
        }
        else
        {
            o.OnPress = () => {
                this.PopModel();
            }
        }
        m.addChild(o);
        m.addChild(elem);
        this.poplayer.addChild(m);
    }
    GetPopTag(): string {
        if (this.poplayer.getChildCount() == 0)
            return null;
        return (this.poplayer.getChild(this.poplayer.getChildCount() - 1) as any).tag
    }
    PopModel() {
        let last = this.poplayer.getChildCount() - 1;
        if (last >= 0)
            this.poplayer.removeChildAt(last);
    }
}